package com.tencent.iov.cowin.befsale.clue.controller.clue;

import com.tencent.iov.cowin.befsale.clue.controller.clue.assembler.ClueFailAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.AddClueFailRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.DeleteClueFailRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.QueryClueFailRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.UpdateClueFailRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueFailResponse;
import com.tencent.iov.cowin.befsale.clue.domain.clue.po.ClueFail;
import com.tencent.iov.cowin.befsale.clue.service.clue.ClueFailService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.common.utils.BasePropertyInjection;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 线索战败审批信息表_Controller层
 * @author: whp
 * @created: 2021-12-21 16:16:11
 * @version: 1.0
 */
@RestController
@Api(tags = "线索战败审批信息表Controller")
@RequestMapping(value = "/v1/clueFail", produces = MediaType.APPLICATION_JSON_VALUE)
public class ClueFailController {

    @Autowired
    private ClueFailService clueFailService;

    /**
     * 通过ID获取详细信息
     *
     * @param: id
     * @return: ClueFail对象
     */
    @ApiOperation(value = "ClueFail管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
    @RequestMapping(path = "/get_detail_by_id", method = RequestMethod.GET)
    public Response<ClueFailResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1") @RequestParam("id") Long id) {
        return Response.success(ClueFailAssembler.transformPOToResponseVo(clueFailService.getDetailById(id), ClueFailResponse.class));
    }

    /**
     * 单条数据插入ClueFail
     *
     * @param request
     * @return 插入的条数
     */
    @ApiOperation(value = "ClueFail管理-战败申请", httpMethod = "POST", response = Response.class, notes = "add")
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Response<Long> add(@Valid @RequestBody AddClueFailRequest request) {
        BasePropertyInjection.savePropertyInjection(request);
        return Response.success(clueFailService.insert(ClueFailAssembler.transformVOToPO(request, ClueFail.class)));
    }

    /**
     * 批量插入ClueFail
     *
     * @param requests
     * @return 批量插入的条数
     */
    @ApiOperation(value = "ClueFail管理-批量插入ClueFail接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
    @RequestMapping(path = "/add_batch", method = RequestMethod.POST)
    public Response<Integer> addBatch(@Valid @RequestBody List<QueryClueFailRequest> requests) {
        return Response.success(clueFailService.insertBatch(ClueFailAssembler.transformPOToResponseVoList(requests, ClueFail.class)));
    }

    /**
     * 通过ID修改信息接口
     *
     * @param: request
     * @return: 修改的条数
     */
    @ApiOperation(value = "ClueFail管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Response<Integer> update(@Valid @RequestBody UpdateClueFailRequest request) {
        return Response.success(clueFailService.update(ClueFailAssembler.transformVOToPO(request, ClueFail.class)));
    }

    /**
     * 通过ID删除数据
     *
     * @param request
     * @return 删除的条数
     */
    @ApiOperation(value = "ClueFail管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public Response<Integer> delete(@Valid @RequestBody DeleteClueFailRequest request) {
        return Response.success(clueFailService.delete(ClueFailAssembler.transformVOToPO(request, ClueFail.class)));
    }

    /**
     * 根据条件查询对象list列表
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "ClueFail管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
    @RequestMapping(path = "/get_list_by_param", method = RequestMethod.POST)
    public Response<List<ClueFailResponse>> getListByParam(@RequestBody QueryClueFailRequest request) {
        List<ClueFail> responseList = clueFailService.getListByParam(ClueFailAssembler.transformVOToPO(request, ClueFail.class));
        return Response.success(ClueFailAssembler.transformPOToResponseVoList(responseList, ClueFailResponse.class));
    }

    /**
     * 根据条件查询对象Page记录
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "ClueFail管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_page_by_param", method = RequestMethod.POST)
    public Response<PageResponse<ClueFailResponse>> getPageByParam(@RequestBody PageRequest<QueryClueFailRequest> request) {
        PageResponse<ClueFail> clueFailPageResponse = clueFailService.getPageByParam(ClueFailAssembler.transformVOToPOPage(request, ClueFail.class));
        return Response.success(ClueFailAssembler.transformPOToResponseVoPage(clueFailPageResponse, ClueFailResponse.class));
    }
}